package com.serli.sample.data.runner.view;

import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.model.Model;

import com.serli.sample.data.runner.WicketApplication;
import com.serli.sample.data.runner.WicketSession;
import com.serli.sample.data.runner.domain.Trip;
import com.serli.sample.data.runner.service.TripService;

/**
 * Homepage
 */
public class HomePage extends WebPage {

	private static final long serialVersionUID = 1L;

	// TODO Add any page properties or variables here

	/**
	 * Constructor that is invoked when page is invoked without a session.
	 * 
	 * @param parameters
	 *            Page parameters
	 */
	public HomePage(final PageParameters parameters) {

		List<Trip> trips = ((WicketApplication)getApplication()).getAllTrip();
		TripList tripList = new TripList("tripList", Model.valueOf(trips));
		add(tripList);

		Trip trip = null;
		String tripName = ((WicketSession)getSession()).getSelectedName();
		if(tripName != null) {
			trip = ((WicketApplication)getApplication()).getTrip(tripName);
		}
		TripDetail tripDetail = new TripDetail("tripDetail", new Model(trip));
		add(tripDetail);
	}
}
